package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.ruoyi.oa.domain.OaProject;
import com.ruoyi.oa.domain.vo.OaFinanceTravelVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.vo.OaProjectVo;
import com.ruoyi.oa.domain.bo.OaProjectBo;
import com.ruoyi.oa.service.IOaProjectService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目
 *
 * @author ruoyi
 * @date 2023-04-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/project")
public class OaProjectController extends BaseController {

    private final IOaProjectService iOaProjectService;

    /**
     * 查询项目列表
     */
//    @SaCheckPermission("system:project:list")
    @GetMapping("/list")
    public TableDataInfo<OaProjectVo> list(OaProjectBo bo, PageQuery pageQuery) {
        return iOaProjectService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出项目列表
     */
//    @SaCheckPermission("system:project:export")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaProjectBo bo, HttpServletResponse response) {
        List<OaProjectVo> list = iOaProjectService.queryList(bo);
        ExcelUtil.exportExcel(list, "项目", OaProjectVo.class, response);
    }

    /**
     * 获取项目详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:project:query")
    @GetMapping("/{id}")
    public R<OaProjectVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iOaProjectService.queryById(id));
    }

    /**
     * 新增项目
     */
//    @SaCheckPermission("system:project:add")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaProjectBo bo) {
        return iOaProjectService.insertByBo(bo);
    }

    /**
     * 修改项目
     */
//    @SaCheckPermission("system:project:edit")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaProjectBo bo) {
        return toAjax(iOaProjectService.updateByBo(bo));
    }

    /**
     * 删除项目
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:project:remove")
    @Log(title = "项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iOaProjectService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 获取所有项目信息
     */
    @Log(title = "获取所有项目信息", businessType = BusinessType.UPDATE)
    @GetMapping("/getProjectName")
    public R<List<OaProject>> getProjectName() {
        return R.ok(iOaProjectService.getProjectName());
    }


//    @RequestMapping("/queryByProjectName")
//    public R<OaFinanceTravelVo> queryByProjectName(@RequestBody Map<String,Object> map) {
//        return R.ok(iOaFinanceTravelService.queryByProjectName(map.get("projectName").toString()));
//    }



}
